package com.xcx.robot.mirai.key;

import com.xcx.robot.util.DateUtils;
import lombok.extern.slf4j.Slf4j;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

/**
 * @Author: 邢晨旭
 * @Date: 2021/6/21 13:40
 * @Description:
 */
@Slf4j
public class DrawImg {
    private static final int width = 500;

    private static final int height = 292;

    public static BufferedImage openServer(String server) {
        //得到图片缓冲区
        FileInputStream fileInputStream = null;
        try {
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            File file = new File("bg.jpeg");
            if (!file.exists()) {
                throw new Exception("背景存放地址有误");
            }
            fileInputStream = new FileInputStream(file);
            BufferedImage image2 = ImageIO.read(fileInputStream);
            //得到它的绘制环境(这张图片的笔)
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.fillRect(0, 0, width, height);
            //设置颜色
            g2.setColor(Color.WHITE);
            // 将图片大小设置为大约4cm*4cm 具体根据纸张大小设定
            g2.drawImage(image2, 0, 0, 500, 292, null);
            g2.drawRect(0, 0, width - 1, height - 1);
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            //设置字体:字体、字号、大小
            g2.setFont(new Font("黑体", Font.BOLD, 20));
            g2.setPaint(new Color(0, 0, 0, 64));//阴影颜色
            g2.drawString(server, 110, 150);//先绘制阴影
            //设置背景颜色
            g2.setColor(Color.BLACK);
            //向图片上写字符串
            g2.drawString(server, 110, 150);
            g2.setPaint(new Color(0, 0, 255, 64));//阴影颜色
            g2.drawString("开服啦", 200, 150);
            g2.setFont(new Font("黑体", Font.BOLD, 20));
            g2.setColor(Color.blue);
            g2.drawString("开服啦", 200, 150);
            g2.setFont(new Font("黑体", Font.BOLD, 15));
            g2.setPaint(new Color(0, 2, 255, 64));//阴影颜色
            g2.drawString(DateUtils.getDateTime(), 110, 170);
            g2.setColor(Color.blue);
            g2.drawString(DateUtils.getDateTime(), 110, 170);
            g2.dispose();
            return bi;
        } catch (Exception e) {
            log.error("开服监控图片生成出错", e);
            return null;
        }
    }



}
